package org.budo.support.apache.commons.fileupload.servlet.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

/**
 * @author lmw
 */
public class ServletFileUploadUtil {
    public static List<FileItem> parseRequest(ServletFileUpload servletFileUpload, HttpServletRequest request) {
        try {
            return servletFileUpload.parseRequest(request);
        } catch (FileUploadException e) {
            throw new RuntimeException(e);
        }
    }

    public static List<FileItem> parseRequest(HttpServletRequest request) {
        ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
        return parseRequest(servletFileUpload, request);
    }
}